<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <script src="../layui/layui.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../js/jquery.js"></script>
    <script src="../js/myAjax.js"></script>
    <script src="../js/util/popup.js"></script>
    <script src="../js/util/getGroupLeader.js"></script>
</head>
<body>
<div style="margin-left: 50px; margin-top: 120px">
    <div type="hidden" id="groupId"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">组名：</label>
        <div class="layui-input-inline">
            <input type="text" name="title" required lay-verify="required" id="name" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择框</label>
        <div class="layui-input-inline">
            <select name="member" lay-verify="required"  id="leader" style="width: 190px;height: 30px">

            </select>
        </div> <span id="add-member"></span>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">成立时间：</label>
        <div class="layui-input-inline"> <!-- 注意：这一层元素并不是必须的 -->
            <input type="text" readonly  class="layui-input" id="establishedTime">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="editAdd('/group/edit',getData())">立即提交</button>
            <button type="reset" onclick="resetEdit('/html/groupEdit.html')" class="layui-btn layui-btn-primary">
                点击重置
            </button>
        </div>
    </div>
</div>
<script>
    //获取页面输入的值，传递给保存的方法editAdd（）；
    function getData() {
        let data = {
            id:sessionStorage.getItem("groupId"),
            name: $("#name").val(),
            leader: $("#leader").find("option:selected").text(),
            establishedTime: $("#establishedTime").val(),
        }
        return data;//必须带返回值
    }
    //点击编辑页面，通过id去后台查询获得数据给编辑页面进行赋值
    let id = sessionStorage.getItem("groupId")
    findById('/group/findById',id);
    function findById(url,id) {
        let result = myAjax(url,'post',{id:id});
        $("#name").val(result.name);
        $("#establishedTime").val(result.establishedTime);
    }
</script>
</body>
</html>